手机推拉流iOS SDK文档

目录

  1. 如何接入
  2. 推流配置
  3. 拉流步骤
  4. 错误码说明
  5. SDK和Demo下载

如何接入

环境需求:

  • iOS系统版本8.0及以上
  • 机器型号 iPhone 5S及以上
  • CPU架构支持 ARMv7、ARMv7s、ARM64
  • 集成工具 Xcode8.0及以上
  • bitcode 关闭

接入步骤

  1. IJKMediaFramework.frameworkMDLiveEngine.frameworkIJKMediaFrameworkWithSSL.frameworkAccelerate.frameworkAudioToolbox.framework等库文件和资源文件拖入项目文件夹

  2. 在项目根路径下运行如下命令:

    pod init
    

    然后在修改根目录下的Profile文件添加以下依赖:

    pod 'MBProgressHUD', '~> 1.1.0'
    pod 'Masonry'
    

    之后在项目跟路径下运行如下命令:

    pod install
    
  3. Build Settings中关闭Bitcode

  4. info.plist中添加获取摄像头、麦克风和相册权限的描述

推流配置

推流配置如下例:

MDPushConfig pushConfig;
memset(&pushConfig, 0, sizeof(pushConfig));
//设置音频采样率
pushConfig.audioSampleRate = 44100;
pushConfig.channel = 2;
//设置视频码率
pushConfig.videoBitRate = 9000* 1000;
//设置音频码率
pushConfig.audioBitRate = 96 * 1000;
//设置分辨率 默认为720P
pushConfig.pushSize =  Preset1080x720;
//设置推流类型 默认音视频推流
pushConfig.streamType = MDPUSH_DEFAULT;
//设置推流地址
pushConfig.config.rtmpConfig.pushUrl = @"rtmp://xxxxx/xxxx/xxxx";

在配置好推流配置后,调用下例代码可以弹出推流页面:

//创建MDPusher
_livepush = [[MDLiveEngine alloc]init];
//设置摄像头 默认为前置摄像头
[_livepush startCaptureWithSizeType:kCaptureSize1280_720 fps:30 position:AVCaptureDevicePositionFront];
//设置推流方向是否为竖屏 默认为NO
_livepush.outputOrientation = UIInterfaceOrientationPortrait;
//设置推流配置
[_livepush startStreamPushWithConfig:pushConfig];

退出销毁

[_livepush stopStreamPush];
附加功能

1.静音

[_livepush enableMixingAudioStream:!btn.selected];

2.开关闪光灯

if (_livepush.cameraPosition == AVCaptureDevicePositionBack) 
{
   _livepush.torchOn = btn.selected;
}
else
{
    UIAlertView* view = [[UIAlertView alloc]initWithTitle:@"提示"       message:@"闪关灯只在后置摄像头有效" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [view show];
}

3.切换摄像头

if (_livepush.cameraPosition == AVCaptureDevicePositionBack) 
{
    _livepush.cameraPosition = AVCaptureDevicePositionFront;
}else
{
   _livepush.cameraPosition = AVCaptureDevicePositionBack;
}

拉流步骤

  1. 获取playerView,设置播放地址并播放

    _player = [[IJKFFMoviePlayerController alloc]initWithContentURLString:self.textfield.text withOptions:nil];
    [_player setOptionIntValue:1 forKey:@"videotoolbox" ofCategory:kIJKFFOptionCategoryPlayer];
    [_player setPlayerOptionIntValue:5000 forKey:@"max_cached_duration"];
    _player.view.frame = self.view.bounds;
    [_player prepareToPlay];
    

    重新播放

    if (_player) 
    {
    [_player stop];
    [_player shutdown];
    _player = nil;
    }
    [self playVideo];
    

    结束播放

    if (_player) {
    [_player stop];
    [_player shutdown];
    _player = nil;
    }
    

    错误码说明

    //包发送错误 kLiveEngineSendPacketError //与服务器握手失败 kLiveEngineConnectError //停止推流错误 kLiveEngineStopPushError //视频录制错误 kLiveEngineInfoRecodeError //电话,闹钟等音频抢占导致音频终止 kLiveEngineInfoAudioInterruption

iOS SDK 下载 iOS Demo 下载

results matching ""

    No results matching ""